package com.dong.servlet;

import java.io.IOException;


import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.dong.service.UserService;

public class ActiveUserServlte extends HttpServlet {
	
	/**
	 * 
	 */
	private static final long serialVersionUID = -3001519731872655727L;

	public void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {

		doPost(request, response);
	}

	/**
	 * The doPost method of the servlet. <br>
	 *
	 * This method is called when a form has its tag value method equals to post.
	 * 
	 * @param request the request send by the client to the server
	 * @param response the response send by the server to the client
	 * @throws ServletException if an error occurred
	 * @throws IOException if an error occurred
	 */
	public void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		request.setCharacterEncoding("utf-8");
		
		String uid = request.getParameter("uid");
		String validateCode = request.getParameter("validateCode");
		boolean flag ;
		UserService userService = new UserService();
		 try {
			flag = userService.validateUser(uid, validateCode);
			if(flag) {
				//激活成功,转向激活结果页面
				request.setAttribute("message", new String("激活成功，请点击下面的登录链接进行登录！"));
				request.getRequestDispatcher("activateSuc.jsp").forward(request, response);
			} else {
				request.setAttribute("message", new String("激活失败，请重新点击激活链接进行激活！"));
				request.getRequestDispatcher("activateFail.jsp").forward(request, response);
			}
		} catch (Exception e) {
			e.printStackTrace();
			//发生异常，转向错误页面
			request.setAttribute("message", new String("服务器错误！"));
			request.getRequestDispatcher("error.jsp").forward(request, response);
		}		
	}

}
